<template>
  <div>
    <page-dialog
      :title="dialogInfo.title"
      v-model:visible="shows"
      :width="dialogInfo.width"
      :bt-loading="dialogInfo.btLoading"
      :bt-list="dialogInfo.btList"
      :top="'10px'"
      class="depotStorageDialog"
    >
      <div class="layui-col-md5" style="padding-right: 10px; width: 40%">
        <NewPageFilter
          v-model:query="detailFilterInfo.query.queryMap"
          :query-more-json="true"
          :filter-list="detailFilterInfo.searchList"
          :filter-btn="detailFilterInfo.searchBtn"
        >
        </NewPageFilter>
        <!-- 表格 -->
        <dialog-table
          ref="detailTable"
          :refresh="detailTableInfo.refresh"
          :init-curpage="detailTableInfo.initCurpage"
          v-model:data="detailTableInfo.data"
          class="detailTable"
          :check-box="false"
          :pager="false"
          :highlight-row="true"
          :tab-index="true"
          :max-height="580"
          :field-list="detailTableInfo.fieldList"
          :handle="detailTableInfo.handle"
          :query="detailFilterInfo.query"
          @handleEvent="detailHandleEvent"
        >
        </dialog-table>
      </div>
      <div class="layui-col-md5" style="width: 60%">
        <div v-if="isSysGroup" class="select-depot-storage layui-row">
          <!-- 条件栏 -->
          <NewPageFilter
            v-model:query="leftFilterInfo.query.queryMap"
            :query-more-json="true"
            :filter-list="leftFilterInfo.searchList"
            :filter-btn="leftFilterInfo.searchBtn"
          >
          </NewPageFilter>
          <dialog-table
            ref="productTable"
            :refresh="leftTableInfo.refresh"
            :init-curpage="leftTableInfo.initCurpage"
            v-model:data="leftTableInfo.data"
            :api="leftTableInfo.api"
            class="productTable"
            :reserve-selection="true"
            :listen-height="false"
            :max-height="isSysGroup ? 225 : 550"
            :selectable="selectable"
            :query="leftFilterInfo.query"
            :field-list="leftTableInfo.fieldList"
            :highlight-row="isSysGroup ? highlightRow : false"
            :check-box="checkBox"
            :is-row-click-select="!isSysGroup"
            @handleEvent="leftHandleEvent"
          >
          </dialog-table>
        </div>
        <div class="layui-row select-depot-storage">
          <NewPageFilter
            v-model:query="rightFilterInfo.query.queryMap"
            :query-more-json="true"
            :filter-list="rightFilterInfo.searchList"
            :filter-btn="rightFilterInfo.searchBtn"
          >
            <template v-slot:filter-fill>
              <el-checkbox
                v-if="
                  rightTableInfo.data.length
                    ? rightTableInfo.data[0].codeType === 1 ||
                      rightTableInfo.data[0].codeType === 4
                    : false
                "
                v-model="rightFilterInfo.data.fill"
                label="一键填充"
                border
                @change="changeNumberAll"
              ></el-checkbox>
            </template>
          </NewPageFilter>
          <el-form ref="tableForm" :model="rightTableInfo" style="width: 100%">
            <dialog-table
              ref="batchNumberTable"
              :refresh="rightTableInfo.refresh"
              :init-curpage="rightTableInfo.initCurpage"
              v-model:data="rightTableInfo.data"
              :api="rightTableInfo.api"
              :reserve-selection="true"
              :listen-height="false"
              :max-height="250"
              :query="rightFilterInfo.query"
              :field-list="rightTableInfo.fieldList"
              :check-box="checkBox"
              @handleEvent="rightHandleEvent"
            >
              <template v-slot:col-editQty="scope">
                <el-form-item
                  v-if="scope.row.codeType === 1 || scope.row.codeType === 4"
                  class="margin-bottom"
                  @click.stop.native=""
                >
                  <div class="page-table-input-number-wrapper">
                    <div class="page-table-input-number-left">
                      <div class="page-table-input-number-item">
                        <el-form-item>
                          <el-input-number
                            v-model.lazy="scope.row.largeUnitQty"
                            style="width: 100%; margintop: 18px"
                            clearable
                            controls-position="right"
                            :precision="
                              scope.row.qtyOperateMode === 0 ||
                              scope.row.qtyOperateMode === 2
                                ? 0
                                : systemConfig.qty_show_precision
                            "
                            :min="0"
                            :max="largeMax(scope.row)"
                            @change="changeLarge($event, scope.row)"
                          />
                        </el-form-item>
                        <div class="page-table-input-number-item-unite">
                          {{ scope.row.unitName }}
                        </div>
                      </div>
                      <div
                        v-if="
                          scope.row.unitConvertCoefficient > 1 &&
                          scope.row.qtyOperateMode === 2
                        "
                        class="page-table-input-number-item"
                      >
                        <el-form-item>
                          <el-input-number
                            v-model.lazy="scope.row.smallUnitQty"
                            style="width: 100%; margintop: 18px"
                            clearable
                            controls-position="right"
                            :precision="0"
                            :min="0"
                            :max="smallMax(scope.row)"
                          />
                        </el-form-item>
                        <div class="page-table-input-number-item-unite">
                          {{ scope.row.calcUnitName }}
                        </div>
                      </div>
                    </div>
                    <div
                      v-if="scope.row.qtyOperateMode === 2"
                      class="page-table-input-number-right"
                    >
                      {{ $fn.qtyFormatter(scope.row.editQty) }}
                    </div>
                  </div>
                </el-form-item>
                <span
                  v-else-if="
                    scope.row.codeType === 2 || scope.row.codeType === 3
                  "
                  >{{ $fn.qtyFormatter(scope.row.editQty) }}</span
                >
              </template>
            </dialog-table>
          </el-form>
        </div>
      </div>
    </page-dialog>
  </div>
</template>

<script setup name="selectDepotStorage">
import PageDialog from '@/components/PageDialog/index'
import DialogTable from '@/components/DialogTable/index'

import { getDepotStockCustomizeListPage } from '@/api/stock.js'
import { getCustomizeSetting } from '@/api/customize'
import { getUseApplicationDetail } from '@/api/use'
import utils from '@/common/js/utils'
import * as _ from 'lodash'

const { proxy } = getCurrentInstance()
const emit = defineEmits()
const props = defineProps({
  highlightRow: {
    type: Boolean,
    default: true,
  },
  checkBox: {
    type: Boolean,
    default: true,
  },
  api: {
    type: Function,
    default: getDepotStockCustomizeListPage,
  },
  orderId: {
    type: Number,
  },
  excludeProductIds: {
    type: Array,
    default: function () {
      return []
    },
  },
  excludeQueryList: {
    type: Array,
    default: function () {
      return []
    },
  },
  showPrice: {
    type: Boolean,
  },
  showDialog: {
    type: Boolean,
  },
  leftTableKey: {
    type: String,
    default:
      'productPageWithDepotStockLeft-com.slip.spd.entity.vo.stock.DepotStockVO',
  },
  rightTableKey: {
    type: String,
    default:
      'productPageWithDepotStockRight-com.slip.spd.entity.vo.stock.DepotStockVO',
  },
  query: {
    type: Object,
    default: function () {
      return {}
    },
  },
  depotId: {
    type: Number,
    default: -2,
  },
})

const systemConfig = ref(proxy.$store.state.permission.systemConfig)
const selectRow = ref(new Map())
const selectRowProdectId = ref('')
const searchObj = ref('')
const groupArr = ref('')
const clickRow = ref({})
const clickRowMap = ref(new Map())
const selectBatchRow = ref(new Map())
// 过滤相关配置)
const isSysGroup = ref(false)
//明细相关配置
const detailFilterInfo = reactive({
  query: {
    customizeUserVO: {},
    queryMap: {
      orderId: {
        queryType: 'EQUALS',
        queryCategory: 'AND',
        value: props.orderId,
      },
    },
    queryParams: {},
  },
  searchList: [],
  searchBtn: [{ type: 'button', label: '搜索', event: detailSearch }],
})
//领用明细
const detailTableInfo = reactive({
  refresh: 1,
  initCurpage: 1,
  height: '30%',
  data: [],
  fieldList: [],
})

const leftFilterInfo = reactive({
  query: {
    queryParams: {
      //stockAvailableCalcQtyGt: 0
    },
    queryMap: {
      depotId: {
        queryType: 'EQUALS',
        value: props.depotId,
      },
    },
    customizeUserVO: {},
  },
  searchList: [],
  searchBtn: [{ type: 'button', label: '搜索', event: leftSearch }],
})
// 表格相关
const leftTableInfo = reactive({
  refresh: 1,
  initCurpage: 1,
  api: undefined,
  height: '60%',
  data: [],
  fieldList: [],
})
const rightFilterInfo = reactive({
  query: {
    queryParams: {
      stockAvailableCalcQtyGt: 0,
    },
    queryMap: {
      depotId: {
        queryType: 'EQUALS',
        value: props.depotId,
      },
    },
    customizeUserVO: {},
  },
  data: {
    fill: false,
  },
  searchList: [],
  searchBtn: [
    { type: 'button', label: '搜索', event: rightSearch },
    { type: 'slot', value: 'fill' },
  ],
})
// 表格相关
const rightTableInfo = reactive({
  refresh: 1,
  initCurpage: 1,
  api: undefined,
  height: '60%',
  data: [],
  fieldList: [],
})
// 弹窗相关
const dialogInfo = reactive({
  title: '选择库存产品',
  btLoading: false,
  width: '90%',
  btList: [
    { label: '关闭', event: handleClose, show: true },
    {
      label: '保存',
      type: 'primary',
      disabled: true,
      event: save,
      show: true,
    },
  ],
})

const shows = computed({
  get() {
    return props.showDialog
  },
  set(newValue) {
    emit('update:showDialog', newValue) // 更新父组件shows
  },
})

watch(
  () => rightTableInfo.data,
  (val) => {
    if (val.length) {
      val.forEach((row) => {
        let smallUnitQty = parseFloat(row.smallUnitQty || 0)
        let unitConvertCoefficient = row.unitConvertCoefficient || 1
        let largeUnitQty = parseFloat(row.largeUnitQty || 0)
        let editCalcQty = proxy.$fn.accAdd(
          proxy.$fn.accMul(largeUnitQty, unitConvertCoefficient),
          smallUnitQty
        )
        let editQty = proxy.$fn.accDiv(editCalcQty, unitConvertCoefficient)
        row['editCalcQty'] = editCalcQty
        row['editQty'] = editQty
        row.sumAmount = proxy.$fn.accDiv(
          proxy.$fn.accMul(editCalcQty, row.price),
          unitConvertCoefficient
        )
        let newData = ''
        let key = ''
        if (isSysGroup.value) {
          key = setKey(clickRow.value)
          newData = selectBatchRow.value.get(key)
        } else {
          key = selectRowProdectId.value
          newData = selectRow.value.get(key)
        }
        if (newData && newData.length) {
          newData.forEach((item) => {
            if (item.id === row.id) {
              item.largeUnitQty = row.largeUnitQty
              item.smallUnitQty = row.smallUnitQty
              item.editCalcQty = row.editCalcQty
              item.editQty = row.editQty
              item.sumAmount = row.sumAmount
            }
          })
          selectBatchRow.value.set(key, newData)
        }
      })
    }
  },
  {
    immediate: true,
    deep: true,
  }
)

let obj = {
  price: {
    label: '单价',
    value: 'price',
    type: 'column',
    componentType: 'price',
    permission: !props.showPrice,
    formatter: proxy.$fn.TripartiteMethod,
    hidden: true,
    show: false,
  },
  sumAmount: {
    label: '总金额',
    value: 'sumAmount',
    formatter: proxy.$fn.TripartiteMethod,
    type: 'column',
    componentType: 'price',
    permission: !props.showPrice,
    hidden: true,
    show: false,
  },
  defaultSupplierPrice: {
    label: '默认供应商价格',
    value: 'defaultSupplierPrice',
    type: 'column',
    componentType: 'price',
    permission: !props.showPrice,
    formatter: proxy.$fn.TripartiteMethod,
    hidden: true,
    show: false,
  },
}
let detailObj = {
  storeStockQty: {
    label: '领入仓库可用数量',
    value: 'storeStockQty',
    hidden: true,
    type: 'column',
    formatter: utils.qtyFormatter,
  },
  exportStockQty: {
    label: '领出仓库可用数量',
    value: 'exportStockQty',
    hidden: true,
    type: 'column',
    formatter: utils.qtyFormatter,
  },
}
detailTableInfo.fieldList = Object.values({
  ...proxy.$fn.deepClone(proxy.$fieldfList.FieldList),
  ...proxy.$fn.deepClone(detailObj),
})
leftTableInfo.fieldList = Object.values({
  ...proxy.$fn.deepClone(proxy.$fieldfList.FieldList),
  ...proxy.$fn.deepClone(obj),
})
rightTableInfo.fieldList = Object.values({
  ...proxy.$fn.deepClone(proxy.$fieldfList.FieldList),
  ...proxy.$fn.deepClone(obj),
  editQty: {
    label: '数量',
    value: 'editQty',
    type: 'slot',
    componentType: 'number',
    show: false,
    hidden: true,
    minWidth: '250px',
  },
})
detailFilterInfo.searchList = Object.values({
  ...proxy.$fn.deepClone(proxy.$fieldfList.FieldList),
  commonName: {
    label: '通用名称',
    value: 'commonName',
    componentType: 'input',
    show: true,
    hidden: true,
  },
  statusValue: {
    show: false,
    hidden: true,
  },
  deptName: {
    show: false,
    hidden: true,
  },
})
rightFilterInfo.searchList = Object.values({
  ...proxy.$fn.deepClone(proxy.$fieldfList.FieldList),
  ...proxy.$fn.deepClone(obj),
  commonName: {
    label: '通用名称',
    value: 'commonName',
    componentType: 'input',
    show: false,
    hidden: true,
  },
})
leftFilterInfo.searchList = Object.values({
  ...proxy.$fn.deepClone(proxy.$fieldfList.FieldList),
  ...proxy.$fn.deepClone(obj),
  commonName: {
    label: '通用名称',
    value: 'commonName',
    componentType: 'input',
    show: false,
    hidden: true,
  },
})
getDetailsCustomize()
getLeftCustomize()
getRightCustomize()

function changeNumberAll(type) {
  let data = []
  if (!isSysGroup.value) {
    data = [...selectRow.value.values()].map((item) => item.id)
  } else {
    let keyArr = [...clickRowMap.value.keys()]
    keyArr.forEach((item) => {
      let details = selectBatchRow.value.get(item)
      details.forEach((el) => {
        data.push(el.id)
      })
    })
  }
  rightTableInfo.data.forEach((item) => {
    if (data.includes(item.id)) {
      let unitConvertCoefficient = item.unitConvertCoefficient || 1
      if (type) {
        if (item.codeType === 4 || item.codeType === 1) {
          let clickRow = detailTableInfo.data.filter(
            (row) => row.productId === item.productId
          )
          let num = clickRow[0].applicationCalcQty
          if (num > 0) {
            item.calcQty = num
            if (item.qtyOperateMode === 2) {
              item.largeUnitQty = parseInt(
                item.calcQty / unitConvertCoefficient
              )
              item.smallUnitQty = parseInt(
                item.calcQty % unitConvertCoefficient
              )
            } else {
              item.largeUnitQty = item.calcQty
              item.smallUnitQty = 0
            }
          }
        }
      } else {
        item.largeUnitQty = 0
        item.smallUnitQty = 0
      }
    }
  })
}
function largeMax(row) {
  if (row.qtyOperateMode === 2) {
    return parseInt(row.stockAvailableCalcQty / row.unitConvertCoefficient)
  } else {
    return row.stockAvailableQty
  }
}
function smallMax(row) {
  let largeUnitQty = parseInt(
    row.stockAvailableCalcQty / row.unitConvertCoefficient
  )
  if (largeUnitQty === 0 || row.largeUnitQty === largeUnitQty) {
    return parseInt(row.stockAvailableCalcQty % row.unitConvertCoefficient)
  } else {
    return row.unitConvertCoefficient - 1
  }
}
function changeLarge(e, row) {
  let largeUnitQty = parseInt(
    row.stockAvailableCalcQty / row.unitConvertCoefficient
  )
  if (row.qtyOperateMode === 2 && row.unitConvertCoefficient > 1) {
    if (largeUnitQty > 0 && e === largeUnitQty) {
      let smallUnitQty = parseInt(
        row.stockAvailableCalcQty % row.unitConvertCoefficient
      )
      if (row.smallUnitQty > smallUnitQty) {
        row.smallUnitQty = smallUnitQty
      }
    }
  }
}
//获取领用明细
function getDetailsList() {
  getUseApplicationDetail(detailFilterInfo.query).then((resp) => {
    if (resp && resp.success) {
      detailTableInfo.data = resp.data
    }
  })
}
function detailSearch() {
  getDetailsList()
}
async function detailHandleEvent(event, data) {
  if ((await event) === 'tableClickRow') {
    rightTableInfo.data = []
    if (data) {
      leftFilterInfo.query.queryMap.productId.value = data.productId
      if (!isSysGroup.value) {
        let key = data.productId
        selectRowProdectId.value = key
        rightTableInfo.api = props.api
        getRightList()
      } else {
        leftTableInfo.api = props.api
        getLeftList()
      }
    }
  }
}
// 获取左侧产品列表
function getLeftList() {
  proxy.$nextTick(() => {
    leftTableInfo.refresh = Math.random()
  })
}
function leftSearch() {
  const tableInfo = leftTableInfo
  tableInfo.initCurpage = Math.random()
  tableInfo.refresh = Math.random()
}

function getRightList() {
  rightTableInfo.refresh = Math.random()
}
function rightSearch() {
  const tableInfo = rightTableInfo
  tableInfo.initCurpage = Math.random()
  tableInfo.refresh = Math.random()
}
function selectable() {
  if (isSysGroup.value) {
    return false
  } else {
    return true
  }
}
function save() {
  //条码类型 code_type：1无码，2系统唯一码，3原厂码，4批次码
  let _selectBatchRow = []
  if (isSysGroup.value) {
    let keyArr = [...clickRowMap.value.keys()]
    let valueArr = [...clickRowMap.value.values()]
    keyArr.forEach((item, index) => {
      let details = selectBatchRow.value.get(item)
      let data = setDetails(details)
      details = data.data
      valueArr[index].isChoice = true
      valueArr[index].details = details
      valueArr[index].sumAmount = data.sumAmount
      valueArr[index].calcQty = data.calcQty
      valueArr[index].qty = data.qty
      valueArr[index].largeUnitQty = data.largeUnitQty
      valueArr[index].smallUnitQty = data.smallUnitQty
    })
    _selectBatchRow = valueArr
  } else {
    let _selectRow = [...selectRow.value.values()]
    let arr = []
    if (_selectRow.length) {
      _selectRow.forEach((row) => {
        row.forEach((item) => {
          arr.push(item)
        })
      })
      _selectBatchRow = setDetails(arr).data
      let newSelectBatchRow = proxy.$fn.deepClone(_selectBatchRow)
      _selectBatchRow.forEach((row, index) => {
        let item = newSelectBatchRow[index]
        row.details = [item]
      })
    }
  }
  let newData = _.groupBy(_selectBatchRow, (item) => {
    return item.productId
  })
  let commonName = []
  let keys = Object.keys(newData)
  keys.forEach((key) => {
    let row = detailTableInfo.data.find((item) => item.productId == key)
    let value = newData[key]
    let calcQty = 0
    if (value && value.length) {
      value.forEach((item) => {
        calcQty = proxy.$fn.accAdd(item.calcQty, calcQty)
      })
    }
    if (calcQty > row.applicationCalcQty) {
      commonName.push(row.commonName)
    }
  })
  if (commonName.length) {
    proxy.$alert(
      `产品【${commonName}】的操作数量不能大于申请数量，请修改`,
      '提示',
      {
        confirmButtonText: '确定',
      }
    )
    return
  }
  handleClose()
  emit('callback', _selectBatchRow)
}
function setDetails(data) {
  let sunAmount = 0
  let calcQty = 0
  let largeUnitQty = 0
  let smallUnitQty = 0
  let qty = 0
  data.forEach((item) => {
    item.isChoice = true
    item.depotStockId = item.id
    item.calcQty = item.editCalcQty
    item.qty = item.editQty
    calcQty = proxy.$fn.accAdd(item.calcQty || 0, calcQty)
    largeUnitQty = proxy.$fn.accAdd(item.largeUnitQty || 0, largeUnitQty)
    smallUnitQty = proxy.$fn.accAdd(item.smallUnitQty || 0, smallUnitQty)
    qty = proxy.$fn.accAdd(item.qty || 0, qty)
    item.sumAmount = proxy.$fn.accDiv(
      proxy.$fn.accMul(item.calcQty, parseFloat(item.price)),
      item.unitConvertCoefficient
    )
    sunAmount += item.sumAmount
  })
  return {
    data: data,
    sumAmount: sunAmount,
    qty: qty,
    calcQty: calcQty,
    largeUnitQty: largeUnitQty,
    smallUnitQty: smallUnitQty,
  }
}
async function leftHandleEvent(event, data) {
  switch (await event) {
    case 'tableClickRow':
      if (data && data.id) {
        let newData = proxy.$fn.deepClone(data)
        newData.key = setKey(newData)
        clickRow.value = data
        for (let key in searchObj.value) {
          searchObj.value[key].value = newData[key]
        }
        rightFilterInfo.query.queryMap = {
          ...rightFilterInfo.query.queryMap,
          ...searchObj.value,
        }
        data.depotStockId = data.id
        rightTableInfo.api = props.api
        rightSearch()
        let key = setKey(clickRow.value)
        clickRowMap.value.set(key, data)
        if (!selectBatchRow.value.has(key)) {
          proxy.$refs['productTable'].toggleRowSelection(clickRow.value, true)
        }
      }
      break
  }
}
function setKey(item) {
  let key = ''
  groupArr.value &&
    groupArr.value.forEach((row, index) => {
      key =
        key + item[row.value] + (index === groupArr.value.length - 1 ? '' : '&')
    })
  return key
}
function rightHandleEvent(event, data) {
  if (event === 'list' && data.length) {
    let selectData = ''
    if (isSysGroup.value) {
      let key = setKey(clickRow.value)
      selectData = selectBatchRow.value.get(key)
    } else {
      let selectRow = selectRow.value
      let key = selectRowProdectId.value
      selectData = selectRow.get(key)
    }
    data.forEach((row) => {
      if (row.codeType === 1 || row.codeType === 4) {
        row.largeUnitQty = 0
        row.smallUnitQty = 0
        row.sumAmount = 0
      } else if (row.codeType === 2 || row.codeType === 3) {
        row.editCalcQty = row.calcQty
        row.editQty = row.qty
      }
      if (selectData && selectData.length) {
        selectData.forEach((item) => {
          if (item.id === row.id) {
            row.largeUnitQty = item.largeUnitQty
            row.smallUnitQty = item.smallUnitQty
            row.editCalcQty = item.editCalcQty
            row.editQty = item.editQty
            row.sumAmount = item.sumAmount
          }
        })
      }
    })
    rightTableInfo.data = data
  }
  if (!isSysGroup.value) {
    let selectRow = selectRow.value
    let key = selectRowProdectId.value
    if (event === 'list') {
      if (data.length > 0) {
        if (!selectRow.has(key)) {
          proxy.$refs['batchNumberTable'].toggleRowSelection(data[0], true)
          rightFilterInfo.data.fill = false
        }
      }
    }
    if (event === 'tableCheck') {
      if (data.length) {
        data = data.filter(Boolean)
        let row = data.filter((item) => item.productId === key)
        if (row.length) {
          selectRow.set(key, row)
        } else {
          selectRow.delete(key)
        }
      } else {
        selectRow.clear()
      }
    }
    if ([...selectRow.value.keys()].length) {
      dialogInfo.btList[1].disabled = false
    } else {
      dialogInfo.btList[1].disabled = true
    }
    return
  }

  switch (event) {
    case 'list':
      let key = setKey(clickRow.value)
      if (data.length && !selectBatchRow.value.has(key)) {
        rightTableInfo.data = data
        if ([...selectBatchRow.value.keys()].length) {
          if (!selectBatchRow.value.has(setKey(data[0]))) {
            proxy.$refs['batchNumberTable'].toggleRowSelection(data[0], true)
            rightFilterInfo.data.fill = false
          }
        } else {
          proxy.$refs['batchNumberTable'].toggleRowSelection(data[0], true)
          rightFilterInfo.data.fill = false
        }
      }
      break
    case 'tableCheck':
      if (data.length) {
        let mapNew = _.groupBy(data, (item) => {
          let key = setKey(item)
          return key
        })
        let key = setKey(clickRow.value)
        if (!Object.keys(mapNew).includes(key)) {
          selectBatchRow.value.delete(key)
          clickRowMap.value.delete(key)
          //rightTableInfo.data = [];
          proxy.$refs['productTable'].toggleRowSelection(clickRow.value, false)
          proxy.$refs['productTable'].setCurrentRow()
        } else {
          clickRowMap.value.set(key, clickRow.value)
          proxy.$refs['productTable'].toggleRowSelection(clickRow.value, true)
          for (let key in mapNew) {
            selectBatchRow.value.set(key, mapNew[key])
          }
        }
      } else {
        let key = setKey(clickRow.value)
        selectBatchRow.value.delete(key)
        clickRowMap.value.delete(key)
        proxy.$refs['productTable'].toggleRowSelection(clickRow.value, false)
        //rightTableInfo.data = [];
      }
      break
  }
  let len = [...selectBatchRow.value.keys()].length
  if (len) {
    dialogInfo.btList[1].disabled = false
  } else {
    dialogInfo.btList[1].disabled = true
  }
}
// 关闭弹窗前的回调
function handleClose() {
  shows.value = false
  emit('reset')
}
function getDetailsCustomize() {
  let param = {
    tableKey:
      'useApplicationOrderAuditDetail-com.slip.spd.entity.vo.use.UseApplicationOrderDetailVO',
  }
  getCustomizeSetting(param).then((res) => {
    if (res && res.success) {
      let data = res.data
      detailFilterInfo.query.customizeUserVO = res.data
      detailTableInfo.fieldList = proxy.$fn.setFieldList(
        detailTableInfo.fieldList,
        data.detail
      )
      let searchInfo = proxy.$fn.setSearchList(
        detailFilterInfo.searchList,
        data.detail
      )
      detailFilterInfo.searchList = searchInfo.searchList
      detailFilterInfo.searchList.forEach((item) => {
        item.event = detailSearch
      })
      detailFilterInfo.query.queryMap = {
        ...proxy.$fn.deepClone(detailFilterInfo.query.queryMap),
        ...proxy.$fn.deepClone(searchInfo.queryMap),
        ...proxy.$fn.deepClone(props.query),
      }
      detailFilterInfo.query.queryParams = {
        ...detailFilterInfo.query.queryParams,
      }
      getDetailsList()
    }
  })
}
function getLeftCustomize() {
  let tableInfo = leftTableInfo
  let filterInfo = leftFilterInfo
  let param = { tableKey: props.leftTableKey }
  let obj = {}
  let _groupArr = []
  getCustomizeSetting(param).then((res) => {
    if (res && res.success) {
      let data = res.data
      filterInfo.query.customizeUserVO = data
      tableInfo.fieldList = proxy.$fn.setFieldList(
        tableInfo.fieldList,
        data.detail
      )
      let searchInfo = proxy.$fn.setSearchList(
        filterInfo.searchList,
        data.detail
      )
      filterInfo.searchList = searchInfo.searchList
      filterInfo.searchList.forEach((item) => {
        item.event = leftSearch
      })
      isSysGroup.value = false
      for (let key in data.detail) {
        if (data.detail[key].sysGroupLevel > 0) {
          obj[key] = {
            queryType: 'EQUALS',
            queryCategory: 'AND',
            ignoreEmptyValue: false,
            value: null,
          }
          _groupArr.push({ value: key })
          isSysGroup.value = true
        }
      }
      searchObj.value = obj
      groupArr.value = _groupArr
      filterInfo.query.queryMap = {
        ...proxy.$fn.deepClone(searchInfo.queryMap),
        ...proxy.$fn.deepClone(props.query),
        ...proxy.$fn.deepClone(filterInfo.query.queryMap),
      }
      filterInfo.query.queryParams = {
        ...filterInfo.query.queryParams,
      }
      if (isSysGroup.value) {
        filterInfo.query.excludeQueryList = props.excludeQueryList
      } else {
        rightFilterInfo.query.excludeQueryList = props.excludeQueryList
      }
    }
  })
}
function getRightCustomize() {
  let tableInfo = rightTableInfo
  let filterInfo = rightFilterInfo
  let param = { tableKey: props.rightTableKey }
  getCustomizeSetting(param).then((res) => {
    if (res && res.success) {
      let data = res.data
      filterInfo.query.customizeUserVO = data
      tableInfo.fieldList = proxy.$fn.setFieldList(
        tableInfo.fieldList,
        data.detail
      )
      let searchInfo = proxy.$fn.setSearchList(
        filterInfo.searchList,
        data.detail
      )
      filterInfo.searchList = searchInfo.searchList
      filterInfo.searchList.forEach((item) => {
        item.event = leftSearch
      })
      filterInfo.query.queryMap = {
        ...proxy.$fn.deepClone(searchInfo.queryMap),
        ...proxy.$fn.deepClone(props.query),
        ...proxy.$fn.deepClone(filterInfo.query.queryMap),
      }
      // getRightList();
    }
  })
}
</script>

<style scoped lang="scss">
.productTable :deep(.el-table__header-wrapper .el-checkbox) {
  display: none;
}
.productTable
  :deep(.el-checkbox__input.is-disabled.is-checked .el-checkbox__inner) {
  background-color: #6dc1a9;
  border-color: #6dc1a9;
}
.productTable
  :deep(.el-checkbox__input.is-disabled.is-checked .el-checkbox__inner::after) {
  border-color: #ffffff;
}
</style>
<style>
.depotStorageDialog .el-dialog__body {
  max-height: 1000px !important;
}
</style>
